// var myIterable = {}
// myIterable[Symbol.iterator] = function* () {
//     yield 1;
//     yield 2;
//     yield 3;
// };
// let arr = [...myIterable] // [1, 2, 3]
// console.log(arr);

console.log("===========- string -==========");
let str = '6668';
let iterator = str[Symbol.iterator]();
console.log(iterator,'---');

console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());

let arr = [...str];
console.log(arr);

console.log('自定义迭代器-----');
let str1 = new String('6789');
str1[Symbol.iterator] = function() {
    console.log('---this',this);
    return {
        next:function() {
            
            if(this.count > 0) {
                this.count--;
                return {done:false,value:6666};
            }else {
                return {done:true,value:undefined};
            }
        },
        count:6

    }
    
}

let arr1 = [...str1];
console.log(arr1);

console.log('-----需要可迭代对象的语法----');
console.log([...'string']);


console.log('----- 生成器 ----');
let aGeneratorObj = function*() {
    yield 1;
    yield 2;
    yield 3;
}();

console.log(typeof aGeneratorObj[Symbol.iterator]);
console.log(typeof aGeneratorObj.next);

console.log(aGeneratorObj[Symbol.iterator]() === aGeneratorObj);

// Array.prototype[@@iterator]
